<template>
  <div class="app-container flex column">
    <top-title :updateTime="true" :content="content"></top-title>
    <div class="content-wrap f1 flex column">
      <div class="table-operator">
        <a-button @click="handleAdd" type="primary" class="BtnStyle" icon="plus"> 新增 </a-button>
        <a-button @click="batchDel" v-if="selectedRowKeys.length > 0" class="BtnStyle" type="primary" icon="delete">
          批量删除
        </a-button>
      </div>

      <div class="alter flex align-center" style="margin: 0">
        <img src="@/assets/imgs/system/alter_icon.png" alt="" />
        <span>已选择:</span>
        <span v-if="selectionRows.length">{{ selectionRows.length }}</span>
        <span v-if="selectionRows.length" @click="onClearSelected">清空</span>
      </div>
      <a-table
        rowKey="id"
        :columns="columns"
        class="tableList"
        :pagination="false"
        :dataSource="dataSource"
        :loading="loading"
        :expandedRowKeys="expandedRowKeys"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @expandedRowsChange="handleExpandedRowsChange"
      >
        <span slot="action" slot-scope="text, record">
          <a class="operation dropdown-color" @click="handleEdit(record)">编辑</a>

          <a-dropdown>
            <a class="ant-dropdown-link operation dropdown-color">
              更多
              <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;" @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a href="javascript:;" @click="handleAddSub(record)">添加下级</a>
              </a-menu-item>
              <a-menu-item>
                <a href="javascript:;" @click="handleDataRule(record)">数据规则</a>
              </a-menu-item>

              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
        <!-- 字符串超长截取省略号显示 -->
        <span slot="url" slot-scope="text">
          <j-ellipsis :value="text" :length="25" />
        </span>
        <!-- 字符串超长截取省略号显示-->
        <span slot="component" slot-scope="text">
          <j-ellipsis :value="text" />
        </span>
      </a-table>
    </div>
    <permission-modal ref="modalForm" @refresh="modalFormOk"></permission-modal>
    <permission-data-rule-list ref="PermissionDataRuleList" @refresh="modalFormOk"></permission-data-rule-list>
  </div>
</template>

<script>
import { getPermissionList } from '@/api/api'
import topTitle from '@/components/topTitle'
import JEllipsis from '@/components/jeecg/JEllipsis'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import PermissionModal from './modules/PermissionModal'
import PermissionDataRuleList from './PermissionDataRuleList'
export default {
  name: '',
  mixins: [JeecgListMixin],
  components: { topTitle, JEllipsis, PermissionModal, PermissionDataRuleList, },
  data () {
    return {
      content: [['菜单管理']],
      url: {
        list: '',
        delete: '/sys/permission/delete',
        deleteBatch: '/sys/permission/delete_batch',
      },
      columns: [
        {
          title: '菜单名称',
          dataIndex: 'name',
          key: 'name',
          align: 'center',
        },
        {
          title: '菜单类型',
          dataIndex: 'menuType',
          align: 'center',
          key: 'menuType',
          customRender: function (text) {
            if (text == 0) {
              return '菜单'
            } else if (text == 1) {
              return '菜单'
            } else if (text == 2) {
              return '按钮/权限'
            } else {
              return text
            }
          },
        },
        /*{
            title: '权限编码',
            dataIndex: 'perms',
            key: 'permissionCode',
          },*/
        {
          title: 'ICON',
          dataIndex: 'icon',
          align: 'center',
          key: 'icon',
        },
        {
          title: '组件',
          dataIndex: 'component',
          align: 'center',
          key: 'component',
          scopedSlots: { customRender: 'component' },
        },
        {
          title: '路径',
          dataIndex: 'url',
          align: 'center',
          key: 'url',
          scopedSlots: { customRender: 'url' },
        },
        {
          title: '排序',
          dataIndex: 'sortNo',
          align: 'center',
          key: 'sortNo',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
          width: 150,
        },
      ],
      loading: false,
      // 展开的行，受控属性
      expandedRowKeys: [],
    }
  },
  mounted () { },
  methods: {
    loadData () {
      this.dataSource = []
      getPermissionList().then((res) => {
        if (res.code == 200) {
          this.dataSource = res.result
        }
      })
    },
    handleExpandedRowsChange (expandedRows) {
      this.expandedRowKeys = expandedRows
      // console.log(expandedRows, 'expandedRows')
    },
    // 打开数据规则编辑
    handleDataRule (record) {
      this.$refs.PermissionDataRuleList.edit(record)
    },
    handleAddSub (record) {
      this.$refs.modalForm.title = '添加子菜单'
      this.$refs.modalForm.disableSubmit = false
      this.$refs.modalForm.edit({ status: '1', permsType: '1', route: true, parentId: record.id, menuType: 1 })
    },
  },
  destroy () { }
}
</script>

<style scoped lang="less">
</style>
